<?php 
if ( has_post_thumbnail() && is_page()) { 
  echo '<div class="banner">';
  the_post_thumbnail();
  echo '</div>';
}else
{
    if ($post->post_parent != 0){
        $thePostID = get_post_ancestors($post);
        $thePostID = end($thePostID);    
    }else{
        return;
    }
    $thumb_id = get_post_thumbnail_id($thePostID);

    $args = array(
        'post_type' => 'attachment',
        'post_status' => null,
        'post_parent' => $thePostID,
        'include'  => $thumb_id
    ); 

    $thumbnail_image = get_posts($args);
    if ($thumbnail_image && isset($thumbnail_image[0])) {
        echo '<div class="banner">';
        echo '<img src="'.$thumbnail_image[0]->guid.'">';
        echo '</div>';
        //print_r($thumbnail_image[0]);
  }
}

?>